using B.S.XZYData.ErrorCode;
using MediatR;
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

namespace B.S.XZYData.Api.Wrter.Application.Command.Approval
{
    /// <summary>
    /// 处理审批操作命令
    /// </summary>
    public class ProcessApprovalCommand : IRequest<ApiResult<bool>>
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        [Required(ErrorMessage = "流程实例ID不能为空")]
        public int WorkflowInstanceId { get; set; }

        /// <summary>
        /// 操作类型（通过、驳回）
        /// </summary>
        [Required(ErrorMessage = "操作类型不能为空")]
        public string OperationType { get; set; } = string.Empty;

        /// <summary>
        /// 审批意见
        /// </summary>
        public string? Comment { get; set; }

        /// <summary>
        /// 审批人用户名
        /// </summary>
        [Required(ErrorMessage = "审批人不能为空")]
        public string AuditUserName { get; set; } = string.Empty;

        /// <summary>
        /// 审批人ID
        /// </summary>
        public int AuditUserId { get; set; }

        /// <summary>
        /// 审批步骤名称
        /// </summary>
        public string? StepName { get; set; }
    }

    /// <summary>
    /// 重新提交申请命令
    /// </summary>
    public class ResubmitApplicationCommand : IRequest<ApiResult<bool>>
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        [Required(ErrorMessage = "流程实例ID不能为空")]
        public int WorkflowInstanceId { get; set; }

        /// <summary>
        /// 申请人用户名
        /// </summary>
        [Required(ErrorMessage = "申请人不能为空")]
        public string ApplicantUserName { get; set; } = string.Empty;

        /// <summary>
        /// 修改说明
        /// </summary>
        public string? ModifyRemark { get; set; }
    }

    /// <summary>
    /// 撤回申请命令
    /// </summary>
    public class WithdrawApplicationCommand : IRequest<ApiResult<bool>>
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        [Required(ErrorMessage = "流程实例ID不能为空")]
        public int WorkflowInstanceId { get; set; }

        /// <summary>
        /// 申请人用户名
        /// </summary>
        [Required(ErrorMessage = "申请人不能为空")]
        public string ApplicantUserName { get; set; } = string.Empty;

        /// <summary>
        /// 撤回原因
        /// </summary>
        public string? WithdrawReason { get; set; }
    }

    /// <summary>
    /// 批量审批命令
    /// </summary>
    public class BatchProcessApprovalCommand : IRequest<ApiResult<BatchProcessResult>>
    {
        /// <summary>
        /// 流程实例ID列表
        /// </summary>
        [Required(ErrorMessage = "流程实例ID列表不能为空")]
        public int[] WorkflowInstanceIds { get; set; } = Array.Empty<int>();

        /// <summary>
        /// 操作类型（通过、驳回）
        /// </summary>
        [Required(ErrorMessage = "操作类型不能为空")]
        public string OperationType { get; set; } = string.Empty;

        /// <summary>
        /// 审批意见
        /// </summary>
        public string? Comment { get; set; }

        /// <summary>
        /// 审批人用户名
        /// </summary>
        [Required(ErrorMessage = "审批人不能为空")]
        public string AuditUserName { get; set; } = string.Empty;

        /// <summary>
        /// 审批人ID
        /// </summary>
        public int AuditUserId { get; set; }

        /// <summary>
        /// 审批步骤名称
        /// </summary>
        public string? StepName { get; set; }
    }

    /// <summary>
    /// 批量处理结果
    /// </summary>
    public class BatchProcessResult
    {
        /// <summary>
        /// 成功处理的数量
        /// </summary>
        public int SuccessCount { get; set; }

        /// <summary>
        /// 失败处理的数量
        /// </summary>
        public int FailCount { get; set; }

        /// <summary>
        /// 失败的详细信息
        /// </summary>
        public List<BatchProcessError> Errors { get; set; } = new List<BatchProcessError>();
    }

    /// <summary>
    /// 批量处理错误信息
    /// </summary>
    public class BatchProcessError
    {
        /// <summary>
        /// 流程实例ID
        /// </summary>
        public int WorkflowInstanceId { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrorMessage { get; set; } = string.Empty;
    }
} 